package com.educate.service.impl;

import com.educate.dao.PersonalDao;
import com.educate.pojo.User;
import com.educate.service.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.security.Security;

/**
 * @Author: ZJQ
 * @DateTime: 2021/12/21 9:34
 * @Description: 个人中心ServiceImpl
 */
@Service
public class PersonalServiceImpl implements PersonalService {

    @Autowired
    PersonalDao personalDao;

    @Override
    public User getPersonInfoByUsername(String username) {
        User user = personalDao.selectAll(username);
        return user;
    }

    @Override
    public boolean updatePersonal(User user) {
        user.setId(Long.parseLong(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString()));
        return personalDao.updateMsg(user) == 1;
    }

    /**
     * 更新头像
     * @param path
     */
    @Override
    public void updateAvatar(String path) {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        personalDao.updateAvatarByUsername(path,username);
    }

}
